package com.tgpms.web.tongfei.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tgpms.web.tongfei.entity.InPointParts;
import com.tgpms.web.tongfei.dao.InPointPartsMapper;
import com.tgpms.web.tongfei.service.IInPointPartsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.Date;
import java.util.UUID;
import java.time.LocalDateTime;
import com.tgpms.common.Result;
import com.tgpms.exception.ExceptionExplain;
import com.tgpms.util.Common;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jl
 * @since 2020-11-25
 */
@Service
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, rollbackFor = Exception.class)
public class InPointPartsServiceImpl implements IInPointPartsService {

	@Autowired
	private InPointPartsMapper iInPointPartsMapper;
	
	/**
		新增
	*/
	@Override
	public Result<String> addInPointParts(InPointParts en) {
		String id = Common.nowTimeFomat("yyyyMMddHHmmss")+UUID.randomUUID().toString().replaceAll("-", "");
		en.setId(id);
		en.setInsertDate(new Date());
		int i = iInPointPartsMapper.insert(en);
		if(i==1) {
			return Result.OK(ExceptionExplain.SUCCESS_BY_INSERT.getExplain(), id);
		}else {
			return Result.ERROR(ExceptionExplain.ERROR_BY_INSERT.getExplain());
		}
	}
	
	/**
		更新
	*/
	@Override
	public Result<String> updateInPointParts(InPointParts en) {
		int i = iInPointPartsMapper.updateById(en);
		if(i==1) {
			return Result.OK(ExceptionExplain.SUCCESS_BY_UPDATE.getExplain());
		}else {
			return Result.ERROR(ExceptionExplain.ERROR_BY_UPDATE.getExplain());
		}
	}
	
	/**
		根据主键删除
	*/
	@Override
	public Result<String> deleteInPointParts(Serializable id) {
		int i = iInPointPartsMapper.deleteById(id);
		if(i==1) {
			return Result.OK(ExceptionExplain.SUCCESS_BY_DELETE.getExplain());
		}else {
			return Result.ERROR(ExceptionExplain.ERROR_BY_DELETE.getExplain());
		}
	}

	@Override
	public InPointParts getInPointPartsByRowstamp(String rowstamp) {
		return iInPointPartsMapper.selectOne(new LambdaQueryWrapper<InPointParts>().eq(InPointParts::getRowstamp,rowstamp));
	}
}
